// DlgHint.cpp : implementation file
//

#include "stdafx.h"
#include "Univue.h"
#include "func.h"
#include "DlgHint.h"


// CDlgHint dialog

void CDlgHint::display(CDC* pdc)
{
	CDC* pDC = pdc;
	if (NULL == pDC)
	{
		pDC = GetDC();
	}

	CDC		memDC;
	CBitmap	B;
	CBrush	br(RGB(255,255,255));
	CPen	P(PS_SOLID, 1, RGB(100, 100, 100));
	CRect	R(0, 0, m_rect.Width(), m_rect.Height());
	CFont	F;

	memDC.CreateCompatibleDC(pDC);
	B.CreateCompatibleBitmap(pDC, R.Width(), R.Height());
	CREATEFONT2(F, m_szFont, m_fntHeight, FW_NORMAL);

	memDC.SelectObject(&B);
	memDC.SelectObject(&br);
	memDC.SelectObject(&P);
	memDC.SelectObject(&F);
	memDC.Rectangle(R);

	R.InflateRect(-3, -3);
	memDC.SetBkMode(TRANSPARENT);
	memDC.SetTextColor(RGB(0, 0, 0));
	memDC.DrawText(m_sHint, m_sHint.GetLength(), R, DT_TOP|DT_LEFT);
	R.InflateRect(3, 3);

	pDC->BitBlt(0, 0, m_rect.Width(), m_rect.Height(), &memDC, 0, 0, SRCCOPY);

	if (pdc == NULL)
	{
		ReleaseDC(pDC);
	}
}

IMPLEMENT_DYNAMIC(CDlgHint, CDialog)

CDlgHint::CDlgHint(int id, LPCTSTR szHint, LPRECT lpRect, LPCTSTR szFont, int fntHeight, CWnd* pParent)
	: CDialog(CDlgHint::IDD, pParent)
{
	m_id = id;
	m_sHint = szHint;
	m_rect = *lpRect;
	m_szFont = szFont;
	m_fntHeight = fntHeight;
	m_nTimer = -1;
}

CDlgHint::~CDlgHint()
{
}

void CDlgHint::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDlgHint, CDialog)
	ON_WM_PAINT()
	ON_WM_TIMER()
	ON_WM_DESTROY()
END_MESSAGE_MAP()


// CDlgHint message handlers

void CDlgHint::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	display(&dc);
}

void CDlgHint::OnTimer(UINT_PTR nIDEvent)
{
	CDialog::OnTimer(nIDEvent);

	if (m_nTimer == nIDEvent)
	{
		m_nTimer = -1;
		OnCancel();
	}
}

BOOL CDlgHint::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_nTimer = SetTimer(1, 2000, NULL);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgHint::OnDestroy()
{
	if (m_nTimer != -1)
	{
		KillTimer(m_nTimer);
	}
	CDialog::OnDestroy();

	// TODO: Add your message handler code here
}
